package cate.game.common.time;

import cate.game.GameBody;
import cate.game.framework.ModuleManager;
import easy.java.time.DateTool;

public class TimeManager implements ModuleManager {

    private GameBody game;

    @Override
    public void initIndependent(GameBody game) throws Exception {
        this.game = game;
    }

    @Override
    public void initDependent() throws Exception {

    }

    public long now() {
        long ts = System.currentTimeMillis();
        if(this.game != null && this.game.status != null && this.game.status.data != null) {
            return this.game.status.data.timeOffset + ts;
        }
        return ts;
    }

    public String nowStr() {
        return DateTool.instance().format(now());
    }

    public void addOffset(long ms) {
        this.game.status.data.timeOffset += ms;
    }

    public void resetOffset(long ms) {
        this.game.status.data.timeOffset = ms;
    }
}
